/**
 * 
 */
package com.yidu.user.view;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.model.ManagePayIn;
import com.yidu.model.ManagePayOut;
import com.yidu.model.Page;
import com.yidu.user.service.ManagePayOutService;

@Controller
@RequestMapping("/payOut")
public class ManagePayOutController {
	@Resource(name="payOutService")
	private ManagePayOutService payOutService;
	
	@RequestMapping("/list")
	public String showList(HttpServletRequest request,Page page,ManagePayOut pay){
		List<ManagePayOut> list = payOutService.getAllPayOut(page,pay);
		request.setAttribute("list", list);
		request.setAttribute("date", page.getName());
		return "payOutList";
	}
	@RequestMapping("/delete")
	public void delete(String payoutId,String usName,HttpServletResponse response) throws IOException{
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/plain");
		int row = payOutService.deleteByPayOutId(payoutId,usName);
		PrintWriter out = response.getWriter();
		if(row>0){
			out.print("ok");
		}
		out.close();
	}
	@ResponseBody
	@RequestMapping("/showUpdate")
	public ManagePayOut showUpdate(ManagePayOut payOut) {
		String id = payOut.getPayoutId();
		ManagePayOut pay = payOutService.showUpdate(id);
		return pay;
	}
	@RequestMapping("/addOrUpdate")
	public String addOrUpdate(ManagePayOut payOut,HttpServletRequest request,Page page){
		page.setUserId(payOut.getUsName());
		payOutService.addPayOut(payOut);
		List<ManagePayOut> list = payOutService.getAllPayOut(page, payOut);
		request.setAttribute("list", list);
		request.setAttribute("date", page.getName());
		return "payOutList";
	}
	
}
